import request  from "@/utils/request";

/**
 * 获取所有流程定义
 * @param params
 * @example:
 * {
 * processDefinitionName: null,
 * startDate: null,
 * endDate: null,
 * processDefinitionVersion: undefined,
 * processDefinitionKey: null,
 * pageNum: 1,
 * pageSize: 10,
 * total: 0
 * }
 */
export function processDefinition(params){
  return request({
    url: '/bpmn/processDefinition',
    method: 'get',
    params: params
  })
}

/**
 * 获取流程定义详情
 * @param params
 * @example:
 * {
 *   deploymentKey: 'deploymentKey',
 *   deploymentVersion: deploymentVersion,
 *   resourceType: 'xml/image'
 * }
 */
export function fileResource(params) {
  return request({
    url: '/bpmn/fileResource',
    method: 'get',
    params: params
  })
}

/**
 * 撤销流程部署
 * @param params
 * @example:
 * {
 *   deploymentId : 'deploymentId',
 *   cascade: false
 * }
 */
export function cancelDeployment(params) {
  return request({
    url: '/bpmn/cancelDeployment',
    method: 'post',
    params: params
  })
}

/**
 * 我的待办
 * @param params
 * @return {*}
 */
export function getMeToDone(params){
  return request({
    url: '/bpmn/getMeToDone',
    method: 'get',
    params: params
  })
}

/**
 * 全部待办
 */
export function getAllToDone(params){
  return request({
    url: '/bpmn/getAllToDone',
    method: 'get',
    params: params
  })
}

/**
 * 完成任务
 * @param params
 * @param data
 * @return {*}
 * data携带参数
 * param携带taskId
 */
export function completeTask(params, data){
  return request({
    url: '/bpmn/completeTask',
    method: 'post',
    params: params,
    data: data
  })
}

/**
 * 获取已办任务
 * @param params
 * @return {*}
 */
export function getCompletedTaskWithMe(params){
  return request({
    url: '/bpmn/getCompletedTaskWithMe',
    method: 'get',
    params: params
  })
}

export function forceTerminateProcessInstance(processInstanceId){
  return request({
    url: '/bpmn/forceTerminateProcessInstance',
    method: 'post',
    params: {
      processInstanceId: processInstanceId
    }
  })
}

/**
 * 获取全部流程实例
 * @param params
 * @return {*}
 */
export function getProcessInstances(params){
  return request({
    url: '/bpmn/getProcessInstances',
    method: 'get',
    params: params
  })
}

/**
 * 我的发起
 * @param params
 * @return {*}
 */
export function getProcessInstanceByUserId(params){
  return request({
    url: '/bpmn/getProcessInstanceByUserId',
    method: 'get',
    params: params
  })
}

/**
 * 驳回流程
 * @param taskId 任务id
 * @return {*}
 */
export function rejected(taskId){
  return request({
    url: '/bpmn/rejected',
    method: 'post',
    params: {
      taskId: taskId
    }
  })
}

/**
 * 获取实时流程图
 * @param processInstanceId 流程实例id
 * @return {*}
 */
export function getProcessDiagram(processInstanceId){
  return request({
    url: '/bpmn/getProcessDiagram',
    method: 'get',
    params: {
      processInstanceId: processInstanceId
    }
  })
}

